package com.example.demo.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.enums.ApiErrorCode;
import com.example.demo.Permission;
import com.example.demo.common.Constant;
import com.example.demo.entity.ProjectEntity;
import com.example.demo.entity.UserEntity;
import com.example.demo.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @DESCRIPTION:
 * @AUTOOR: Lee
 * @DATE: 2022年09月18日 1:13
 */
@RestController
@RequestMapping("/project")
public class ProjectController {

    private final ProjectService projectService;


    @Autowired
    public ProjectController(ProjectService projectService) {
        this.projectService = projectService;
    }


    @PostMapping("/create")
    public R<ProjectEntity> create(@RequestBody ProjectEntity project) {
        ProjectEntity projectEntity = projectService.create(project);
        return R.restResult(projectEntity, ApiErrorCode.SUCCESS.getCode(), "创建项目成功");
    }


    @GetMapping("/get")
    @Permission(value = 7)
    public R<ProjectEntity> get(@RequestAttribute(Constant.SESSION_USER) UserEntity user,
                                @RequestParam("projectId") Integer projectId) {
        ProjectEntity projectEntity = projectService.get(projectId);
        return R.restResult(projectEntity, ApiErrorCode.SUCCESS.getCode(), "查询项目成功");
    }
}
